package com.brand.prisd.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.brand.prisd.R;
import com.brand.prisd.ViewHolder.Type4ViewHolder;
import com.brand.prisd.ViewHolder.Type5ViewHolder;
import com.brand.prisd.ViewHolder.Type6ViewHolder;
import com.brand.prisd.bean.VariableStorage;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ChooseDeviceTypeActivity extends AppCompatActivity {

    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.iv_left_arrow)
    ImageView ivLeftArrow;
    @BindView(R.id.iv_scan)
    ImageView ivScan;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choose_device_type);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        rv.setLayoutManager(new LinearLayoutManager(this));
        rv.setAdapter(new RVAdapter());
    }

    @OnClick({R.id.iv_left_arrow, R.id.iv_scan})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_left_arrow:
                go2MainActivity();
                break;
            case R.id.iv_scan:
                Toast.makeText(this, "待开发...", Toast.LENGTH_SHORT).show();
                break;
        }
    }

    private void go2MainActivity() {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }

    @Override
    public void onBackPressed() {
        go2MainActivity();
    }

    class RVAdapter extends RecyclerView.Adapter {
        @Override
        public int getItemViewType(int position) {
            switch (position) {
                case 0:
                    return VariableStorage.ITEM_VIEW_TYPE_4;
                case 1:
                    return VariableStorage.ITEM_VIEW_TYPE_5;
                default:
                    return VariableStorage.ITEM_VIEW_TYPE_6;
            }
        }

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
            switch (viewType) {
                case VariableStorage.ITEM_VIEW_TYPE_4:
                    return new Type4ViewHolder(LayoutInflater.from(getApplicationContext()).inflate(R.layout.add_device_type4_item, viewGroup, false));
                case VariableStorage.ITEM_VIEW_TYPE_5:
                    return new Type5ViewHolder(LayoutInflater.from(getApplicationContext()).inflate(R.layout.add_device_type5_item, viewGroup, false));
                default:
                    return new Type6ViewHolder(LayoutInflater.from(getApplicationContext()).inflate(R.layout.add_device_type6_item, viewGroup, false));
            }
        }


        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
            if (viewHolder instanceof Type6ViewHolder) {
                Type6ViewHolder type6ViewHolder = (Type6ViewHolder) viewHolder;
                type6ViewHolder.setDataInChooseDeviceTypeActivity(position);
            }
        }

        @Override
        public int getItemCount() {
            return 10;
        }

    }
}
